﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.Data;
using StyleMVVM.DependencyInjection.Impl;

namespace StyleMVVM.DependencyInjection
{
	/// <summary>
	/// To be used on an object that is going to be shared between everyone.
	/// Note: You can not use constructor params on a shared service. If you do 
	/// you get back an instance but it will not be shared with other callers.
	/// </summary>
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
	public class SharedAttribute : Attribute, ILifeCycleContainerProviderAttribute
	{
		/// <summary>
		/// By default this is false and should only be set to true if you want the
		/// shared export to be held for the lifetime of the container. 
		/// Services like IDispatchedMessenger and IReflectionService are true.
		/// </summary>
		[Obsolete("This property is being obsoleted in favor of the SingletonAttribute. It maybe removed in the future")]
		public bool Permanent { get; set; }

		public ILifeCycleContainer ProvideContainer()
		{
			if (Permanent)
			{
				return new PermanentlySharedLifeCycleContainer();
			}
			else
			{
				return new WeakSharedLifeCycleContainer();
			}
		}
	}
}